package com.itheima.pingda.controller;

import com.itheima.pinda.authority.base.R;
import com.itheima.pinda.authority.dozer.DozerUtils;
import com.itheima.pinda.authority.dto.auth.VueRouter;
import com.itheima.pinda.authority.entity.auth.Menu;
import com.itheima.pinda.authority.utils.TreeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

import static com.itheima.pinda.authority.base.R.success;

@RequestMapping("/authority/menu")
@RestController
public class MenuController {

    @Autowired
    private DozerUtils dozer;


    @GetMapping("/router")
    public R<List<VueRouter>> myRouter(@RequestParam(value = "group", required = false) String group,
                                       @RequestParam(value = "userId", required = false) Long userId, HttpServletRequest request) {

        /*if (userId == null || userId <= 0) {
            userId = getUserId();
        }
        if(userId == 0){
            String userToken = request.getHeader("token");
            JwtUserInfo userInfo = jwtTokenServerUtils.getUserInfo(userToken);
            userId = userInfo.getUserId();
        }*/
        /*String s="2019-07-25";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
        }*/
        Menu menu=new Menu();
        menu.setId(104L);
        menu.setName("系统管理");
        menu.setDescribe("权限设置");
        menu.setIsPublic(true);
        menu.setPath("/user");
        menu.setComponent("pinda/user/Index");
        menu.setIsEnable(true);
        menu.setSortValue(0);
        menu.setIcon("el-icon-user-solid");
        menu.setGroup(null);
        menu.setParentId(0L);
        menu.setCreateUser(1L);
        menu.setCreateTime(null);
        menu.setUpdateUser(3L);
        menu.setCreateTime(null);
        List<Menu> menuList=new ArrayList<>();
        System.out.println(menu);
        menuList.add(menu);
        /*List<Menu> list = menuService.findVisibleMenu(group, userId);*/
        List<VueRouter> treeList = dozer.mapList(menuList, VueRouter.class);
        System.out.println("--------");
        System.out.println("--------"+treeList);
        return success(TreeUtil.build(treeList));
    }
}

